﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Coding4Fun.UsbCannon.Phone
{
	public partial class Settings : UserControl
	{
		public Settings(AppSettings settings)
		{
			InitializeComponent();
			_settings = settings;

			if (_settings == null)
				_settings = new AppSettings();

			EndpointUrl.Text = _settings.EndpointUrl;
		}

		AppSettings _settings;
		public delegate void FinishedEventHandler(object sender, EventArgs e);
		public event FinishedEventHandler Finished;

		private void Save_Click(object sender, RoutedEventArgs e)
		{
			// save settings
			_settings.EndpointUrl = EndpointUrl.Text;

			_settings.Save();
			
			if (null != Finished)
				Dispatcher.BeginInvoke(Finished, this, new EventArgs());
		}

		private void Cancel_Click(object sender, RoutedEventArgs e)
		{
			if (null != Finished)
				Dispatcher.BeginInvoke(Finished, this, new EventArgs());
		}
	}
}
